#coding:utf-8


__all__ = [
#'monitor',
'photo',
#'usermanage',
'wirelessdownload',
]


"""
# py2exe打包不能以这种方式包含文件
for module in __all__:
    exec "import %s"%module
"""

#import monitor
import photo
#import usermanage
import wirelessdownload

hunters = {}
renders = {}
operations = {}
def initializeMarket():
    for module_name in __all__:
        module = eval(module_name)
        
        
        for hunter in module.hunters:
            hunters.update(hunter.getWants()) 
            
        for render in module.renders:
            renders.update(render.getWants())
        
        # init operations
        operations.update(module.operations)

        
# 初始化业务映射
initializeMarket()

def iterOperations():
    for item in operations.iteritems():
        yield item

def findProtocol(busstype):
    for operation in operations.values():
        for p in operation:
            if busstype == p.getType():
                return p
            
def hireHunter(busstype):
    if isinstance(busstype, list):
        busstype = "%02x%02x"%(busstype[0], busstype[1])
    assert isinstance(busstype, (str, unicode))
    busstype = busstype.replace(' ', '')
    return hunters.get(busstype, None)
            
def findRender(busstype):
    if isinstance(busstype, list):
        busstype = "%02x%02x"%(busstype[0], busstype[1])
    assert isinstance(busstype, (str, unicode))
    busstype = busstype.replace(' ', '')
    return renders.get(busstype, None)
        
        

